package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.Autofill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;

/**
 * @Description TODO
 * @Author itheima
 * @Date 2023-07-09 15:51
 */
@Mapper
public interface DishMapper {
    /**
     * 根据菜品分类id查询
     * @param CategoryId
     * @return
     */
    @Select("select count(id) from dish where category_id=#{CategoryId}")
    Integer countByCategoryId( long CategoryId);
    /**
     * 新增菜品接口
     * @param dish
     */
    @Autofill
    @Insert("insert into dish (name, category_id, price, image, description, status,create_time, update_time, create_user, update_user)" +"\n"+
            "values (#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void getadd(Dish dish);

    /**
     * 分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 查询菜品表在售状态总数量
     * @param ids
     * @return
     */
    Integer getbystatus(List<Long> ids);

    /**
     * 批量删除
     * @param ids
     */
    void deleteid(List<Long> ids);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from dish where id=#{id}")
    DishVO getbyid(Long id);

    /**
     * 修改菜品
     * @param dish
     */
    @Autofill(OperationType.UPDATE)
    void update(Dish dish);

    List<Dish> list(Dish dish);
@Select("select * from dish where id=#{id}")
    Dish getbydishid(Long dishId);
    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
